import Mock from 'mockjs'
Mock.mock(/\/mock\/cuisine.*/, 'post', (options: any) => {
  const body = JSON.parse(options.body)
  let num = 24 - (body.page - 1) * 5
  console.log(options)
  console.log(options.body)
  num = num > 5 ? 5 : num
  const img1 = 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fhbimg.b0.upaiyun.com%2F62620088daaf8b47e66f8b843e7641de2a4075a43bdf3-brWb6h_fw658&refer=http%3A%2F%2Fhbimg.b0.upaiyun.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1670412706&t=c6dd35c020586ae8a10fd93c0bfea3d0'
  const img2 = 'https://img1.baidu.com/it/u=1753516674,4285586002&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=849'
  const img3 = 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Flmg.jj20.com%2Fup%2Fallimg%2F1114%2F121R0113012%2F20121Q13012-9-1200.jpg&refer=http%3A%2F%2Flmg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1670585307&t=d058a8b02ce7c3ce24b26e1914ba4dd9'
  const img4 = 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fi0.hdslb.com%2Fbfs%2Farticle%2F3fd5172834d879359818db710333c55147a5292e.jpg&refer=http%3A%2F%2Fi0.hdslb.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1670585307&t=736b61565f51601fb36194952de8b4a9'
  const img5 = 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic1.win4000.com%2Fwallpaper%2F2020-04-10%2F5e8fd7e7df2e8.jpg&refer=http%3A%2F%2Fpic1.win4000.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1670585307&t=ade99c24f2faa71805d4f3a5053b180f'
  const img6 = 'https://img0.baidu.com/it/u=3875972442,3590056617&fm=253&fmt=auto&app=138&f=JPEG?w=781&h=500'
  const img7 = 'https://img2.baidu.com/it/u=1801503838,1045656518&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500'
  const img8 = 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F01a0635e60b42aa80120a89552e16e.jpg%401280w_1l_2o_100sh.jpg&refer=http%3A%2F%2Fimg.zcool.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1670585419&t=3fc7f819d4326e623a2b9dfe164ed7fa'
  const img9 = 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg3.doubanio.com%2Fview%2Fnote%2Fl%2Fpublic%2Fp72404043.jpg&refer=http%3A%2F%2Fimg3.doubanio.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1670585419&t=d30a6c7f8427b4d423af5f10fbe6d92f'
  const img10 = 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Flmg.jj20.com%2Fup%2Fallimg%2Ftp02%2F1Z91R13554GT-0-lp.jpg&refer=http%3A%2F%2Flmg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1670585419&t=584c1a791c93f2ebe8947208310ba9f6'
  const imgaes = [img1, img2, img3, img4, img5, img6, img8, img7, img9, img10,]
  let data = Mock.mock({
    [`list|${num}`]: [
      {
        check: false,
        'name|1': ['男士餐', '女士餐', '工作餐'],
        'singlePrice|1': [45, 15, 78, 122],
        'price1|1': [45, 12, 64, 63, 26, 32, 66, 33],
        'price2|1': [15, 22, 54, 87, 63, 78, 112, 17],
        'price3|1': [89, 62, 45, 25, 49, 32, 49, 54],
        'bill|1': imgaes,
        'brief|1': ['李大宝', '张三', '李四'],
        time: '@DATETIME("yyyy-MM-dd HH:mm:ss")',
      },

    ],
    total: 24,
    pageSize: 5,
  })
  if (body.input) {
    if (!isNaN(body.input)) {
// @ts-ignore
      data.list = data.list.map((item) => {
        item.singlePrice = body.input
        return item
      })
      data.total *=0.5
    }else{ 
      let namelist =['男士餐', '女士餐', '工作餐']
      namelist=  namelist.filter(item=>{
        return item.includes(body.input)
      })
      if(namelist[0]){
        // @ts-ignore
        data.list = data.list.map((item) => {
         const num = Math.floor(Math.random()*namelist.length)
          item.name = namelist[num]
          return item
        })
        data.total *= namelist.length/3
       
      }
      else if(!namelist[0]){
        let brieflist =['李大宝', '张三', '李四']
        brieflist=  brieflist.filter(item=>{
        return item.includes(body.input)
      })
      if(brieflist[0]){
        // @ts-ignore
        data.list = data.list.map((item) => {
         const num = Math.floor(Math.random()*brieflist.length)
          item.brief = brieflist[num]
          return item
        })
        data.total *= brieflist.length/3
       
      }
      else{
        data.list=[]
      }
      }
      else{
        data.list=[]
      }


     
    }
  }
  return {
    data,
    code: 200,
    message: '请求餐品列表列表成功',
  }
})


Mock.mock(/\/mock\/image.*/, 'post', (options: any) => {

  const img1 = 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fhbimg.b0.upaiyun.com%2F62620088daaf8b47e66f8b843e7641de2a4075a43bdf3-brWb6h_fw658&refer=http%3A%2F%2Fhbimg.b0.upaiyun.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1670412706&t=c6dd35c020586ae8a10fd93c0bfea3d0'
  const img2 = 'https://img1.baidu.com/it/u=1753516674,4285586002&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=849'
  const img3 = 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Flmg.jj20.com%2Fup%2Fallimg%2F1114%2F121R0113012%2F20121Q13012-9-1200.jpg&refer=http%3A%2F%2Flmg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1670585307&t=d058a8b02ce7c3ce24b26e1914ba4dd9'
  const img4 = 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fi0.hdslb.com%2Fbfs%2Farticle%2F3fd5172834d879359818db710333c55147a5292e.jpg&refer=http%3A%2F%2Fi0.hdslb.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1670585307&t=736b61565f51601fb36194952de8b4a9'
  const img5 = 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic1.win4000.com%2Fwallpaper%2F2020-04-10%2F5e8fd7e7df2e8.jpg&refer=http%3A%2F%2Fpic1.win4000.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1670585307&t=ade99c24f2faa71805d4f3a5053b180f'
  const img6 = 'https://img0.baidu.com/it/u=3875972442,3590056617&fm=253&fmt=auto&app=138&f=JPEG?w=781&h=500'
  const img7 = 'https://img2.baidu.com/it/u=1801503838,1045656518&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500'
  const img8 = 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F01a0635e60b42aa80120a89552e16e.jpg%401280w_1l_2o_100sh.jpg&refer=http%3A%2F%2Fimg.zcool.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1670585419&t=3fc7f819d4326e623a2b9dfe164ed7fa'
  const img9 = 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg3.doubanio.com%2Fview%2Fnote%2Fl%2Fpublic%2Fp72404043.jpg&refer=http%3A%2F%2Fimg3.doubanio.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1670585419&t=d30a6c7f8427b4d423af5f10fbe6d92f'
  const img10 = 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Flmg.jj20.com%2Fup%2Fallimg%2Ftp02%2F1Z91R13554GT-0-lp.jpg&refer=http%3A%2F%2Flmg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1670585419&t=584c1a791c93f2ebe8947208310ba9f6'
  const imgaes = [img1, img2, img3, img4, img5, img6, img8, img7, img9, img10,]
  const data = Mock.mock({
    list: [
      {
        check: false,
        'bill|1': imgaes,

      },

    ],

  })
  return {
    data,
    code: 200,
    message: '请求餐品列表列表成功',
  }
})